package com.hrvsr.processor;

import java.io.UnsupportedEncodingException;
import java.util.List;

import com.hrvsr.common.Request;
import com.hrvsr.common.Response;
import com.hrvsr.common.Result;

public class HtmlResponseRrocessor implements ResponseProcessor  {

	@SuppressWarnings("unchecked")
	@Override
	public <T> Result<T> processResponse(Response response) {
		@SuppressWarnings("rawtypes")
		HtmlResult htmlResult = new HtmlResult<String>();
		htmlResult.resp = response;
		return htmlResult;
	}
	
	static class HtmlResult<T> implements Result<String> {
		private Response resp;
		@Override
		public Request getRequest() {
			return resp.getRequest();
		}

		@Override
		public boolean isSuccess() {
			return resp.getStatusCode() == 200;
		}

		@Override
		public String getResult() {
			try {
				return new String(resp.getContent(), "utf-8");
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}

		@Override
		public boolean needsRetry() {
			return false;
		}

		@Override
		public boolean needsPipeline() {
			return isSuccess();
		}

		@Override
		public List<Request> getNextRequests() {
			return null;
		}
		
	}

}
